#include "audio_file_phonon.h"

#include "../plok-model/artist.h"
#include "../plok-model/album.h"

#include <QStringList>

#include <cassert>

namespace plok {

    Audio_file_phonon::Audio_file_phonon (std::string fileName) :
            Audio_file (fileName)
    {
        connect (&m_mediaObject, SIGNAL (metaDataChanged (void)), this, SLOT (on_metaDataChanged (void)));

        m_mediaObject.setCurrentSource( QString::fromStdString( fileName ) );
    }

    Audio_file_phonon::~Audio_file_phonon (void)
    {
    }

    void Audio_file_phonon::on_metaDataChanged (void)
    {
        emit updateInfo();
    }

    std::string Audio_file_phonon::get_artist_from_tag()
    {
        std::string artist = "unknown";

        QStringList string_list = m_mediaObject.metaData("ARTIST");

        if (string_list.size())
            artist = string_list[0].toStdString();

        return artist;

    }
    std::string Audio_file_phonon::get_album_from_tag()
    {
        std::string album = "unknown";

        QStringList string_list = m_mediaObject.metaData("ALBUM");

        if (string_list.size())
            album = string_list[0].toStdString();

        return album;
    }
    std::string Audio_file_phonon::get_title_from_tag()
    {
        std::string title = "unknown";

        QStringList string_list = m_mediaObject.metaData("TITLE");

        if (string_list.size())
            title = string_list[0].toStdString();

        return title;
    }
    std::string Audio_file_phonon::get_release_date_from_tag()
    {
        std::string date = "unknown";

        QStringList string_list = m_mediaObject.metaData("DATE");

        if (string_list.size())
            date = string_list[0].toStdString();

        return date;
    }
    std::string Audio_file_phonon::get_genre_from_tag()
    {
        std::string genre = "unknown";

        QStringList string_list = m_mediaObject.metaData("GENRE");

        if (string_list.size())
            genre = string_list[0].toStdString();

        return genre;
    }

    long long int Audio_file_phonon::get_duration()
    {
        return m_mediaObject.totalTime();
    }

}
